<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var merge = function (intervals) {
            var res = []
            intervals.sort((a, b) => a[0] - b[0])
            res.push(intervals[0])
            for (let i=1;i<intervals.length;i++){
                if(intervals[i][0]<=res[res.length-1][0]&&intervals[i][1]>=res[res.length-1][0]&&intervals[i][1]<=res[res.length-1][1]){
                    res[res.length-1][0] = intervals[i][0]
                }else if(intervals[i][1]<=res[res.length-1][1]&&intervals[i][0]>=res[res.length-1][0]){
                    
                }else if(intervals[i][0]>=res[res.length-1][0]&&intervals[i][1]>=res[res.length-1][1]&&intervals[i][0]<=res[res.length-1][1]){
                    res[res.length-1][1] = intervals[i][1]
                }else if(intervals[i][0]<=res[res.length-1][0]&&intervals[i][1]>=res[res.length-1][1]){
                    res[res.length-1] = intervals[i]
                }else{
                    res.push(intervals[i])
                }
            }
            return res
        };
        console.log(merge([[2,3],[4,5],[6,7],[8,9],[1,10]]))
    </script>
</body>

</html>